//
//  LGOrderConfirmHeader.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2025/2/27.
//

#import "LGOrderConfirmHeader.h"

@interface LGOrderConfirmHeader()
/**   */
@property (nonatomic , strong)UIImageView *tipView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIButton *actionBtn;

@end

@implementation LGOrderConfirmHeader

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip16"]];
        [self addSubview:self.tipView];
        
        self.titleLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        [self addSubview:self.titleLabel];
        
        self.actionBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.actionBtn addTarget:self action:@selector(openOrCloseHeader) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.actionBtn];
        
        [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(viewPix(16));
            make.centerY.equalTo(self);
            make.width.height.equalTo(@(viewPix(12)));
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.tipView.mas_right).offset(viewPix(5));
            make.right.equalTo(self).offset(-viewPix(10));
            make.centerY.equalTo(self);
        }];
        
        [self.actionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.bottom.right.equalTo(self);
        }];
    }
    return self;
}

-(void)setSection:(NSInteger)section{
    _section = section;
}

-(void)setModel:(LGOrderConfirmModel *)model{
    _model = model;
    if (model.opened == YES) {
        self.tipView.image = [UIImage imageNamed:@"grayTipDown"];
    }else{
        self.tipView.image = [UIImage imageNamed:@"grayTip16"];
    }
    self.titleLabel.text = [NSString stringWithFormat:@"%@（%@）",model.title,model.nums];
}

-(void)openOrCloseHeader{
    if (self.delegate && [self.delegate respondsToSelector:@selector(openOrCloseSection:model:)]) {
        [self.delegate openOrCloseSection:self.section model:self.model];
    }
}

@end
